/*
 * @Author: c
 * @Date: 2024-01-08 22:15:33
 * @LastEditTime: 2024-03-20 01:23:55
 * @LastEditors: c
 * @Description: 
 * @FilePath: \music-web-backend\src\core\music\category\category.controller.ts
 * https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Body, Controller, Delete, Get, Param, ParseIntPipe, Post, Put, Query } from '@nestjs/common';
import { IOption } from 'src/common/dto/option.dto';
import { SkipAuth } from 'src/core/system/auth/constants';
import { CategoryService } from './category.service';
import { CategoryForm } from './dto/create-category.dto';
import { CategoryPageQuery } from './dto/search.dto';

/**
 * 歌曲分类
 */
@Controller('category')
export class CategoryController {
  constructor(private readonly categoryService: CategoryService) { }

  /**
    * 类别-分页查询
    * @param pageDto 
    * @returns 
    */
  @Get(":id/list")
  getCategoryListById(@Param('id', ParseIntPipe) id: number) {
    return this.categoryService.getCategoryListById(id);
  }
  /**
    * 类别-分页查询
    * @param pageDto 
    * @returns 
    */
  @SkipAuth()
  @Get("page")
  getPage(@Query() pageDto: CategoryPageQuery) {
    return this.categoryService.findAll(pageDto);
  }


  /**
 * 获取类别下拉列表
 *
 * @param queryParams
 */
  @Get("options")
  getCateOptions(): Promise<IOption<string, number>[]> {
    return this.categoryService.getCateOptions();
  }

  /**
* 获取类别下拉列表
*
* @param queryParams
*/
  @Get("alloptions/:id")
  getCateAllOptions(@Param('id') id: any): Promise<IOption<string, number>[]> {
    return this.categoryService.getCateAllOptions(id);
  }

  /**
   * 类别-新增
   * @param pageDto 
   * @returns 
   */
  @Post()
  saveCategory(@Body() categoryForm: CategoryForm) {

    return this.categoryService.saveCategory(categoryForm); //必须return 不然报错终止整个运行的进程
  }


  /**
  * 类别-单条表单数据
  * @param typeCode 
  * @returns 
  */
  @Get(":id/form")
  getCategoryFormData(
    @Param('id', ParseIntPipe) id
  ) {
    return this.categoryService.getCategoryFormData(id);
  }


  /**
   * 类别-修改
   * @param categoryForm 
   * @returns 
   */
  @Put(':categoryId')
  async updateCategory(@Param('categoryId', ParseIntPipe) categoryId: number, @Body() categoryForm: CategoryForm) {

    return await this.categoryService.updateCategory(categoryId, categoryForm); //必须return 不然报错终止整个运行的进程
  }

  /**
   * 类别-删除
   * @param ids 
   * @returns 
   */
  @Delete(':id')
  remove(@Param('id', ParseIntPipe) id: number) {
    return this.categoryService.remove(id);
  }


  // /**
  //  * 类别-批量删除
  //  * @param ids 
  //  * @returns 
  //  */
  // @Delete(':ids')
  // removeIds(@Param('ids') ids: string) {
  //   return this.categoryService.deleteCategorys(ids);
  // }

}
